/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apt;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author PhiNguyen
 */
public class Connect {

    public static void main(String[] args) {
        try {
            Class.forName(("sun.jdbc.odbc.JdbcOdbcDriver"));
            System.out.println("load driver successfully...");
            Properties prop = new Properties();
            prop.put("charSet","UTF-8");
            prop.put("user","sa");
            prop.put("password","1234567");
            Connection conn = DriverManager.getConnection("jdbc:odbc:DataSource",prop);
            System.out.println("got connection.....");
//            Statement state = conn.createStatement();
//            String sql = "SELECT * FROM DSSinhVien";
//            ResultSet result = state.executeQuery(sql);
////            ResultSetMetaData data = result.getMetaData();
//            while (result.next()) {
//                System.out.println(result.getString("ID") + ";" + result.getString("Name")+ ";" + result.getString("Mail")+ ";"+ result.getString("Phone"));
//            }
            
            String str1 = "Nguyen Quang Duy2";
            String str2 = "duy@gmail.com";
            String str3 = "123124sdf";
            
            PreparedStatement pstmt = null;
            String sql = "UPDATE DSSinhVien SET Name = ? WHERE ID = 1";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, str1);
           
            int rowCount = pstmt.executeUpdate();
            conn.close();

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Connect.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }


    }
}
